package cn.stazxr.pane;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Package: cn.stazxr.pane
 *
 * @Author: stazxr
 * @Create: 2023/12/15
 * @Version: v1.0
 **/
public class JOptionPaneTest {
    public static void main(String[] args) {
        JFrame frame = new JFrame("JOptionPaneTest");
        frame.setBounds(500, 500, 600, 300);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int value = JOptionPane.showConfirmDialog(frame, "确认退出吗？", "退出确认", JOptionPane.YES_NO_OPTION);
                System.out.println(value);
                if (value == JOptionPane.OK_OPTION) {
                    System.exit(0);
                }
            }
        });

        frame.setVisible(true);
    }
}
